package com.zhl.learnDH_class.avg_temp

object TemperatureTest {
  def main(args: Array[String]): Unit = {
    val d1 = Array(("bj",29.1),("sh",29.7),("gz",32.0),("sz",33.1));
    val d2 = Array(("bj",28.9),("sh",29.6),("gz",31.8));
    val d3 = Array(("bj",28.7),("sh",29.4),("gz",31.6),("sz",32.7));

    val data:Array[(String,Double)] = d1 ++ d2 ++ d3;
    val grouped:Map[String,Array[(String,Double)]] = data.groupBy(_._1)

    val result1 = grouped.mapValues(t => {
      val totalSum = t.map(_._2).sum
      val length = t.length
      totalSum / length
    })
    result1.foreach(println)


  }

}
